package cos.android.platform;

import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;

public class SoundManager {

	//Sounds
	private static int jump;
	private static int damage;
	private static int fall;
	
	private static SoundPool sounds;

	private static MediaPlayer music;
	//If sound is activated
	private static boolean sound = true;

	public static void loadSound(Context context) {
	    //sound = SilhouPreferences.sound(context); // should there be sound?
	    sounds = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);
	    // load a sound
	    damage = sounds.load(context, R.raw.aahhzz, 1);
	    jump = sounds.load(context, R.raw.salto, 1);
	    fall = sounds.load(context, R.raw.screwed, 1);
	    // the music that is played at the beginning and when there is only 10 seconds left in a game
	    //music = MediaPlayer.create(context, R.raw.music1);
	}
	
	public static void playDamage() {
	    if (!sound) return; // if sound is turned off no need to continue
	    sounds.play(damage, 1, 1, 1, 0, 1);
	}
	
	public static void playJump() {
	    if (!sound) return; // if sound is turned off no need to continue
	    sounds.play(jump, 1, 1, 1, 0, 1);
	}
	
	public static void playFall() {
	    if (!sound) return; // if sound is turned off no need to continue
	    sounds.play(fall, 1, 1, 1, 0, 1);
	}
	
	public static final void playMusic() {
	    if (!sound) return;
	    if (!music.isPlaying()) {
	    music.seekTo(0);
	    music.start();
	    }
	}
	
	public static final void pauseMusic() {
	    if (!sound) return;
	    if (music.isPlaying()) music.pause();
	}
	
	//Call it on destroying the activity
	public static final void release() {
	    if (!sound) return;
	    sounds.release();
	    music.stop();
	    music.release();
	}
	
}
